package com.flyduck.security.vo;

/**
 * <p></p>
 *
 * @author flyduck 2021/7/2
 * @version V1.0
 * @modificationHistory=========================逻辑或功能性重大变更记录
 * @modify by user: flyduck 2021/7/2
 * @modify by reason:{方法名}:{原因}
 **/
public class ApiResult<T> {
    private Boolean success;

    private Integer code;

    private String message;

    private T data;

    /**
     * 成功返回结果
     *
     * @author Liu Hui
     * @date 2020/3/4 17:59
     * @return com.cqvip.springpush.vo.ApiResult<T>
     */
    public static <T> ApiResult<T> success() {
        return success(null);
    }

    /**
     * 成功返回结果
     * 
     * @author Liu Hui
     * @date 2020/3/4 17:59
     * @param [data]
     * @return com.cqvip.springpush.vo.ApiResult<T>
    */
    public static <T> ApiResult<T> success(T data) {
        return new ApiResult<>(true,
                ApiResultCodeEnum.SUCCESS.getCode(),
                ApiResultCodeEnum.SUCCESS.getMessage(),
                data);
    }

    /**
     * 成功返回结果
     * 
     * @author Liu Hui
     * @date 2020/3/4 17:59
     * @param [data, message]
     * @return com.cqvip.springpush.vo.ApiResult<T>
    */
    public static <T> ApiResult<T> success(T data, String message) {
        return new ApiResult<>(true,
                ApiResultCodeEnum.SUCCESS.getCode(),
                message,
                data);
    }

    /**
     * 失败返回结果
     * 
     * @author Liu Hui
     * @date 2020/3/4 17:59
     * @param [message]
     * @return com.cqvip.springpush.vo.ApiResult<T>
    */
    public static <T> ApiResult<T> failed(String message) {
        return new ApiResult<>(false,
                ApiResultCodeEnum.FAILED.getCode(),
                message,
                null);
    }


    /**
     * 未通过验证失败返回结果
     * 
     * @author Liu Hui
     * @date 2020/3/4 18:00
     * @param [message]
     * @return com.cqvip.springpush.vo.ApiResult<T>
    */
    public static <T> ApiResult<T> validateFailed(String message) {
        return new ApiResult<>(false,
                ApiResultCodeEnum.VALIDATE_FAILED.getCode(),
                message,
                null);
    }

    /**
     * 未授权失败返回结果
     * 
     * @author Liu Hui
     * @date 2020/3/4 18:00
     * @param [data]
     * @return com.cqvip.springpush.vo.ApiResult<T>
    */
    public static <T> ApiResult<T> unauthorized(T data) {
        return new ApiResult<>(false,
                ApiResultCodeEnum.UNAUTHORIZED.getCode(),
                ApiResultCodeEnum.UNAUTHORIZED.getMessage(),
                data);
    }

    /**
     * 未有权限失败返回结果
     * 
     * @author Liu Hui
     * @date 2020/3/4 18:06
     * @param [data]
     * @return com.cqvip.springpush.vo.ApiResult<T>
    */
    public static <T> ApiResult<T> forbidden(T data) {
        return new ApiResult<>(false,
                ApiResultCodeEnum.FORBIDDEN.getCode(),
                ApiResultCodeEnum.FORBIDDEN.getMessage(),
                data);
    }

    public ApiResult() {
        super();
    }

    public ApiResult(Boolean success, Integer code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ApiResult{" +
                "success=" + success +
                ", code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
